package com.mapper;

import com.pojo.OssFile;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OssFileMapper {
    @Insert("INSERT INTO file_upload (open_id, user_name, file_name, file_type, oss_file_name, oss_file_url, upload_time, time_stamp, is_delete) " +
            "VALUES (#{of.open_id}, #{of.user_name}, #{of.file_name}, #{of.file_type}, #{of.oss_file_name}, #{of.oss_file_url}, #{of.upload_time}, #{of.time_stamp}, #{of.is_delete})")
    void upLoadFile(@Param("of") OssFile ossFile);

    @Select("SELECT * FROM file_upload WHERE is_delete=0 ")
    List<OssFile> getFileList(); //获取所有文件

    @Select("SELECT * FROM file_upload WHERE open_id = #{open_id} AND is_delete=0 ")
    List<OssFile> getFileByOpenId(String open_id); //获取个人名下所有文件

    @Select("SELECT * FROM file_upload WHERE id = #{id} AND is_delete=0")
    OssFile getFileById(String id); //根据文件id获取单个文件

    @Select("UPDATE file_upload SET is_delete=1 WHERE id=#{id}")
    String deleteFileById(String id);


    @Select("SELECT * FROM file_upload WHERE file_name = #{fileName}")
    List<OssFile> getByExactFile(String fileName);


}
